<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Yahoo! UI Library - Slider Widget</title>
<link rel="stylesheet" type="text/css" href="css/screen.css">
<style type="text/css">
    #ddPicker { position: absolute; background-color: #eeeeee; top: 200px; left: 20px; width: 360px; height: 240px; }
    #ddPicker input { font-size: .85em }
    #pickerHandle { background-color: #bbbbbb; height: 10px; cursor: move; }
    #hueThumb { cursor:default; width:18px; height:18px; z-index: 9; position:absolute; }
    #hueBg {-moz-outline: none; outline:0px none; position:absolute; left:216px; height:198px; width:18px; background:url(img/hue.png) no-repeat; top:18px; }
    #pickerDiv {-moz-outline: none; outline:0px none; position:absolute; left:10px; height:187px; width:188px; background-color:#FF0000; top:20px; }
    #pickerbg { position:absolute; z-index: 1; top:0px; left:0px; } 
    #selector { cursor:default; width:11px; height:11px; z-index: 9; position:absolute; top:0px; left:0px; }
    #valdiv { text-align:right; position:absolute; top: 86px; left:246px; } 
    #swatch { position:absolute; left:260px; top:30px; height:60px; width:60px; border:2px solid #aaaaaa; }
</style>

<!-- Nav and logger start -->

<script type="text/javascript" src="../../build/yahoo/yahoo-min.js" ></script>
<script type="text/javascript" src="../../build/event/event-min.js" ></script>
<script type="text/javascript" src="../../build/dom/dom-min.js" ></script>
<script type="text/javascript" src="../../build/logger/logger-min.js" ></script>
<script type="text/javascript" src="../../build/dragdrop/dragdrop-min.js" ></script>

<script type="text/javascript" src="../../build/animation/animation-min.js" ></script>
<script type="text/javascript" src="js/color.js" ></script>
<script type="text/javascript" src="js/key.js" ></script>

<script type="text/javascript" src="../../build/slider/slider-debug.js" ></script></head>
<body> 
<div id="pageTitle"><h3>Slider Widget</h3></div> 

<div id="container">
  <div id="containerTop">
    <div id="header"><img id="ylogo" src="img/logo.gif" /></div>
    <div id="main">

        <!-- Nav and logger start -->

<style type="text/css">
    #logButtonHeader input { font-size: 80% }

/* logger default styles */
/* font size is controlled here: default 77% */
#yui-log {position:absolute;top:1em;right:1em;font-size:77%;text-align:left;}
/* width is controlled here: default 31em */
.yui-log {background-color:#AAA;border:1px solid black;font-family:monospace;z-index:9000;}
.yui-log p {margin:1px;padding:.1em;}
.yui-log button {font-family:monospace;}
.yui-log .yui-log-hd {padding:.5em;background-color:#575757;color:#FFF;}
/* height is controlled here: default 20em*/
.yui-log .yui-log-bd {width:100%;height:20em;background-color:#FFF;border:1px solid gray;overflow:auto;}
.yui-log .yui-log-ft {margin-top:.5em;margin-bottom:1em;}
.yui-log .yui-log-ft .yui-log-categoryfilters {}
.yui-log .yui-log-ft .yui-log-sourcefilters {width:100%;border-top:1px solid #575757;margin-top:.75em;padding-top:.75em;}
.yui-log .yui-log-btns {position:relative;float:right;bottom:.25em;}
.yui-log .yui-log-filtergrp {margin-right:.5em;}
.yui-log .info {background-color:#A7CC25;} /* A7CC25 green */
.yui-log .warn {background-color:#F58516;} /* F58516 orange */
.yui-log .error {background-color:#E32F0B;} /* E32F0B red */
.yui-log .time {background-color:#A6C9D7;} /* A6C9D7 blue */
.yui-log .window {background-color:#F2E886;} /* F2E886 tan */


</style>

<div id="rightbar">
  <div id="rightBarPad">
    <h3>Links</h3>
    <div id="linkage">
        <ul>
        <li><a href="index.html?mode=dist">Basic Sliders</a></li>
        <li><a href="basic.html?mode=dist">Scale Factor</a></li>
        <li><a href="rgb.html?mode=dist">RGB Slider</a></li>
        <li><a href="rgb2.html?mode=dist">Color Picker</a></li>
        <!--
        <li><a href="dual.html?mode=dist">Dual Thumb Slider</a></li>
        -->
        </ul>
    </div> 


    <script type="text/javascript">

    //<![CDATA[
    YAHOO.example.logApp = function() {
        return {
            init: function() {
                if (YAHOO.widget.Logger) {
                    var reader = new YAHOO.widget.LogReader( "logDiv", 
                            { newestOnTop: true, height: "400px" } );

                    reader._onClickPauseBtn(null, reader);
                }
            }
        };
    } (); 

    YAHOO.util.Event.on(window, "load", YAHOO.example.logApp.init);
    //]]>
    </script>

    <div id="logDiv"></div>

  </div>
</div>
<!-- Nav and logger end -->
 

        <div id="content"> 
          <div class="newsItem"> 
            <h3>HSV Color Picker</h3>
              <p>&nbsp;</p>
<strong>The logger is paused for performance reasons.  Click "Resume" to re-enable it.</strong>
          </div> 
        </div> 
      
    </div>
  </div>
</div>

<div id="ddPicker">
    <div id="pickerHandle">&nbsp;</div>
    <div id="pickerDiv" tabindex="-1" hidefocus="true">
      <img id="pickerbg" src="img/pickerbg.png" alt="" />
      <div id="selector"><img src="img/select.gif" /></div> 
    </div>

     <div id="hueBg" tabindex="-1" hidefocus="true">
      <div id="hueThumb"><img src="img/hline.png" /></div> 
    </div> 

    <div id="valdiv">
        <form name="rgbform">
        <br />
        R <input autocomplete="off" name="rval" id="rval" type="text" value="0" size="3" maxlength="3" />
        H <input autocomplete="off" name="hval" id="hval" type="text" value="0" size="3" maxlength="3" />
        <br />
        G <input autocomplete="off" name="gval" id="gval" type="text" value="0" size="3" maxlength="3" />
        S <input autocomplete="off" name="gsal" id="sval" type="text" value="0" size="3" maxlength="3" />
        <br />
        B <input autocomplete="off" name="bval" id="bval" type="text" value="0" size="3" maxlength="3" />
        V <input autocomplete="off" name="vval" id="vval" type="text" value="0" size="3" maxlength="3" />
        <br />
        <br />
        # <input autocomplete="off" name="hexval" id="hexval" type="text" value="0" size="6" maxlength="6" />
        <br />

        </form>
    </div>

    <div id="swatch">&nbsp;</div>
</div>


<script type="text/javascript">

YAHOO.example.ColorPicker = function() {

    var Slider=YAHOO.widget.Slider;
    var Color=YAHOO.util.Color;
    var Dom=YAHOO.util.Dom;

    var pickerSize=180;
    
    var hue,picker,panel;

    // hue, int[0,359]
    var getH = function() {
        var h = (pickerSize - hue.getValue()) / pickerSize;
        h = Math.round(h*360);
        return (h == 360) ? 0 : h;
    }

    // saturation, int[0,1], left to right
    var getS = function() {
        return picker.getXValue() / pickerSize;
    }

    // value, int[0,1], top to bottom
    var getV = function() {
        return (pickerSize - picker.getYValue()) / pickerSize;
    }

    var swatchUpdate = function() {
        var h=getH(), s=getS(), v=getV();
        YAHOO.log("hsv " + [h,s,v]);

        Dom.get("hval").value = h;
        Dom.get("sval").value = Math.round(s*100);
        Dom.get("vval").value = Math.round(v*100);

        var rgb = Color.hsv2rgb(h, s, v);

        var styleDef = "rgb(" + rgb.join(",") + ")";
        Dom.setStyle("swatch", "background-color", styleDef);

        Dom.get("rval").value = rgb[0];
        Dom.get("gval").value = rgb[1];
        Dom.get("bval").value = rgb[2];

        Dom.get("hexval").value = Color.rgb2hex(rgb[0], rgb[1], rgb[2]);
    };

    var hueUpdate = function(newOffset) {
        YAHOO.log("hue update: " + newOffset , "warn");
        var rgb = Color.hsv2rgb(getH(), 1, 1);
        var styleDef = "rgb(" + rgb.join(",") + ")";
        Dom.setStyle("pickerDiv", "background-color", styleDef);

        swatchUpdate();
    };

    pickerUpdate = function(newOffset) {
        YAHOO.log("picker update [" + newOffset.x + ", " + newOffset.y + "]" , "warn");
        swatchUpdate();
    };

    return {

        init: function () {

            hue = Slider.getVertSlider("hueBg", "hueThumb", 0, pickerSize);
            hue.subscribe("change", hueUpdate);

            picker = Slider.getSliderRegion("pickerDiv", "selector", 
                    0, pickerSize, 0, pickerSize);
            picker.subscribe("change", pickerUpdate);

            hueUpdate(0);

            panel = new YAHOO.util.DD("ddPicker");
            panel.setHandleElId("pickerHandle");

        }
    }
}();

YAHOO.util.Event.on(window, "load", YAHOO.example.ColorPicker.init);

</script>


<!--[if gte IE 5.5000]>
<script type="text/javascript">

// yuck.

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle       
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
         }
      }
   }

YAHOO.util.Event.addListener(window, "load", correctPNG);

</script>
<![endif]-->

</body>
</html>
